package com.smile.stream.stream;

import com.smile.stream.StreamUtil;
import com.smile.stream.pojo.Dish;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/10/7 17:08
 */
public class StreamDemo2 {
    /**
     * 筛选素菜
     * @param args
     */
    public static void main(String[] args) {
        filter();
        distinct();
        limit();
        skipt();

    }

    private static void skipt() {
        Stream.of("张无忌","金毛狮王","赵敏","小昭","周芷若","赵敏")
                .skip(3)
                .forEach(System.out::println);
    }

    private static void limit() {
        Stream.of("张无忌","金毛狮王","赵敏","小昭","周芷若","赵敏")
                .limit(3)
                .forEach(System.out::println);
    }

    private static void distinct() {
        Stream.of("张无忌","金毛狮王","赵敏","小昭","周芷若","赵敏")
                .distinct()
                .forEach(System.out::println);
    }

    private static void filter() {
        List<Dish> collect = StreamUtil
                .getMenu()
                .stream()
                //此处两个filter等价
                .filter(Dish::isVegetarian)
                .filter(v-> v.isVegetarian())
                .collect(Collectors.toList());
        System.out.println(collect);
    }

}
